package top.eggcode.modules.log.store;

import org.springframework.stereotype.Repository;
import top.eggcode.component.query.CriteriaBuilder;
import top.eggcode.component.query.model.PageList;
import top.eggcode.modules.log.model.LoginLogEntity;
import top.eggcode.modules.log.model.LoginLogQuery;

import javax.annotation.Resource;

/**
 * Title:
 * Description: TODO
 * Date: 2021/9/19 13:49
 *
 * @author JiaQi Ding
 * @version 1.0
 */
@Repository
public class LoginLogStore {

    @Resource
    private CriteriaBuilder builder;

    public PageList<LoginLogEntity> page(LoginLogQuery query) {
        return builder.createQuery(LoginLogEntity.class)
                .fromEntity("root")
                .where(condition -> {
                    if (query.getUsername() != null) {
                        condition.likeAny("root.username", query.getUsername());
                    }

                })
                .fetchPage(query);
    }
}
